package com.qinxueit.admin.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qinxueit.admin.api.ParseHtml;
import com.qinxueit.admin.api.SysConfig;
import com.qinxueit.admin.entity.Article;
import com.qinxueit.admin.entity.Chapter;
import com.qinxueit.admin.entity.Sys;
import com.qinxueit.admin.service.ArticleService;
import com.qinxueit.admin.service.ChapterService;
import com.qinxueit.core.utils.Result;
import org.jsoup.nodes.Document;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wangqinxue
 * @since 2021-08-04
 */
@RestController
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;
    @Autowired
    private ChapterService chapterService;

    @GetMapping("/list")
    public Result list(@RequestParam(defaultValue = "1") Integer currentPage) {
        Page page = new Page(currentPage, 10);
        IPage iPage = articleService.page(page, new QueryWrapper<Article>().orderByDesc("create_time"));
        return Result.success(iPage);
    }

    @GetMapping("/detail/{id}")
    public Result detail(@PathVariable(name = "id") Long id) {
        Article article = articleService.getById(id);
        return Result.success(article);
    }

    @GetMapping("/remove/{id}")
    public Result remove(@PathVariable(name = "id") Long id) {
        boolean article = articleService.removeById(id);
        return Result.success(article);
    }

}
